﻿(function (ko) {
    //
    //set up the view model
    //
    ko.chrome = {
        viewModel: function (configuration) {
            this.appIconUrl = configuration.appIconUrl;
            this.appTitle = configuration.appTitle;
            this.appHelpPageUrl = configuration.appHelpPageUrl;
            this.onCssLoaded = configuration.onCssLoaded;
            this.settingsLinks = configuration.settingsLinks;
        }
    };

    //
    // set up the bindings
    //
    ko.bindingHandlers.chrome = {
        //Initialize the chrome, this is only called once
        init: function (element, viewModelAccessor) {
            var viewModel = viewModelAccessor();

            var options = {
                appIconUrl: viewModel.appIconUrl,
                appTitle: viewModel.appTitle,
                appHelpPageUrl: viewModel.appHelpPageUrl,
                onCssLoaded: viewModel.onCssLoaded,
                settingsLinks: viewModel.settingsLinks
            };

            var nav = new SP.UI.Controls.Navigation(
                                    element.id,
                                    options
                                );

            nav.setVisible(true);
        }
    };
})(ko);